package com.veryGood.service.Impl;

import com.veryGood.common.result.R;
import com.veryGood.common.util.MD5Utils;
import com.veryGood.domain.dto.ResetPasswordDTO;
import com.veryGood.domain.pojo.AdminInfo;
import com.veryGood.mapper.SystemMapper;
import com.veryGood.service.SysService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author 张清富
 * @version 1.0
 */
@Service
public class SysServiceImpl implements SysService {
    @Autowired
    private SystemMapper mapper;

    /**
     * 修改密码
     *修改
     * @param resetPasswordDTO
     * @return
     */
    @Override
    public R resetPassword(ResetPasswordDTO resetPasswordDTO) {
        System.out.println(resetPasswordDTO.getUserId());
        if (resetPasswordDTO != null) {
            AdminInfo adminInfo = mapper.selectById(resetPasswordDTO.getUserId());

            //判断密码是否相同
            String oldPassword = MD5Utils.encrypt(resetPasswordDTO.getOldPassword());

            if (!adminInfo.getUserPwd().equals(oldPassword)) {
                return R.error("密码错误");

            }
            //修改密码
            String newPas = MD5Utils.encrypt(resetPasswordDTO.getPassword());
            int result = mapper.resetPassword(newPas,resetPasswordDTO.getUserId());
            if (result > 0) {
                return R.success("修改成功");
            }

        }
        return R.error();
    }

}
